package com.cyx.order.service;

import com.cyx.order.mapper.OrderMapper;
import com.cyx.order.model.OrderInfo;
import com.cyx.product.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;


    public OrderInfo getOrderInfo(Long id) {
        OrderInfo orderInfo = orderMapper.selectOrderById(id);
        Long productId = orderInfo.getProductId();
        ProductInfo productInfo = restTemplate.getForObject("http://localhost:8081/product/{id}", ProductInfo.class, productId);
        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }
}
